package com.study.shengsiyuan.example05;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.stream.ChunkedWriteHandler;

public class MyWebsocketServerInitializer extends ChannelInitializer<SocketChannel> {

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline pl = ch.pipeline(); //连接所有处理器
		pl.addLast(new HttpServerCodec())// http编解码
			.addLast(new ChunkedWriteHandler()) //将完整数据分块写
			.addLast(new HttpObjectAggregator(8192))//将http数据块聚合成一个req 或resp
			.addLast(new WebSocketServerProtocolHandler("/wss")) //ws 请请求路径 例 : ws://localhost:8080/wss
			.addLast(new MyWebsocketServerHandler());
	}

}
